package com.example.merchant.service;

import com.example.merchant.entity.Coupon;
import com.example.merchant.entity.CouponType;
import com.example.merchant.entity.Customer;
import com.example.merchant.entity.Order;

import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;

/**
 * 优惠券服务
 */
public class CouponService {
    private String coupon;

    // TODO 优惠券模板，优惠券





    // TODO 商家新定义一种“满减优惠券”，规则是满20元减5元。
    /*public CouponType fullDiscountCoupon(Order order){
        //Order order = new Order();
        if (order.getMoney()>=20){
            double m =order.getMoney().intValue();
            order.setMoney(m-5);
            System.out.println("使用满减优惠券成功，订单金额为："+order.getMoney());
        }else {
            System.out.println("不满足满减优惠券使用条件");
        }
        return ;

    }*/
    public CouponType fullDiscountCoupon(){
        CouponType couponType = new CouponType();
        couponType.setCouponTypeId(1);
        couponType.setCouponTypeName("满减");
        couponType.setCouponTypeRule(1);//1满减，2直接减
        couponType.setCouponTypeFull(20.00);//满减条件金额
        couponType.setCouponTypeCut(5.00);//减少金额
        return couponType;
    }


    // TODO 商家新定义一种“天天神券”，规则是固定减3元。
    /*public CouponType everydayCoupon(Order order){
        double m =order.getMoney().intValue();
        order.setMoney(m-3);
        System.out.println("使用天天神券成功，订单金额为："+order.getMoney());

    }*/
    public CouponType everydayCoupon(){
        CouponType couponType = new CouponType();
        couponType.setCouponTypeId(2);
        couponType.setCouponTypeName("满减");
        couponType.setCouponTypeRule(2);//1满减，2直接减
        couponType.setCouponTypeCut(3.00);//减少金额
        return couponType;

    }

    // TODO 商家发行“满减优惠券”，共发行20张（优惠券编码可以用随机数生成）
    public ArrayList<Coupon> issuedFullDiscountCoupon(){

        CouponType fullDiscountCoupon = this.fullDiscountCoupon();



        Random r = new Random(1);
        ArrayList<Coupon> fullDiscountCouponArrayList = new ArrayList<>();
        for (int x=1;x<=20;x++){
            Coupon coupon =new Coupon();
            int m =r.nextInt(900000)+100000;
            coupon.setName("满减券");
            coupon.setCoding(m);
            coupon.setCouponTypeId(fullDiscountCoupon.getCouponTypeId());
            coupon.setId(x);
            coupon.setMoney(fullDiscountCoupon.getCouponTypeCut());
            fullDiscountCouponArrayList.add(coupon);
            //System.out.println("优惠券ID"+coupon.getId()+"满减优惠券编码："+coupon.getCoding());

        }
        return fullDiscountCouponArrayList;

    }

    // TODO 商家发行“天天神券”，共发行50张（优惠券编码可以用随机数生成）
    public ArrayList<Coupon> issuedEverydayCoupon(){

        CouponType everydayCoupon = this.everydayCoupon();

        Random r = new Random(1);
        ArrayList<Coupon> everydayCouponArrayList = new ArrayList<>();
        for (int x=1;x<=50;x++){
            Coupon coupon =new Coupon();
            int m =r.nextInt(900000)+100000;
            coupon.setName("天天神券");
            coupon.setCoding(m);
            coupon.setId(x);
            coupon.setCouponTypeId(everydayCoupon.getCouponTypeId());
            coupon.setMoney(everydayCoupon.getCouponTypeCut());
            everydayCouponArrayList.add(coupon);
            //System.out.println("优惠券ID"+coupon.getId()+"天天神券编码："+coupon.getCoding());

        }

        return everydayCouponArrayList;

    }

    // TODO 商家


}
